package com.itheima.stock.service.imp;

import com.itheima.stock.config.StockInfoConfig;
import com.itheima.stock.mapper.StockMarketIndexInfoMapper;
import com.itheima.stock.service.MarketService;
import com.itheima.stock.utils.DateTimeUtil;
import com.itheima.stock.common.domian.InnerMarket;
import com.itheima.stock.vo.result.R;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author: siwukun
 * @date: 2022/05/31
 * @description:
 */

@Service
public class MarketServiceImpl implements MarketService {
    @Autowired
    private StockMarketIndexInfoMapper stockMarketIndexInfoMapper;

    @Autowired
    private StockInfoConfig stockInfoConfig;
    @Override
    public R<List<InnerMarket>> querySelectAll() {
        //1.获取国内A股大盘的id集合
        List<String> inners = stockInfoConfig.getInner();
        //2.获取最近股票交易日期
        Date lastDate = DateTimeUtil.getLastDate4Stock(DateTime.now()).toDate();
        lastDate=DateTime.parse("2021-12-28 09:31:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate();
        //封装响应给我前端
        List<InnerMarket> markets = stockMarketIndexInfoMapper.queryAllMaket(inners,lastDate);
        return R.ok(markets);
    }
}
